import datetime

from peewee import *

db = SqliteDatabase("database.db")
class BaseModel(Model):
    # 主键id
    id=AutoField()
    # 创建时间
    created_time = DateTimeField(default=datetime.datetime.now)

    class Meta:
        database = db

# 班级
class Clazz(BaseModel):
    def __init__(self, id: int=None, name: str=None, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.name = name
        self.id = id

    # 班级名称
    name = CharField(max_length=50)
    # 班级人数
    number = IntegerField(default=0)

# 学生
class Student(BaseModel):
    def __init__(self, id: int=None, stuno: str=None, name: str=None, clazzid: int=None, clazzname: str=None,
                 birth: str=None, gender: str=None, phone: str=None, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.id = id
        self.stuno = stuno
        self.name = name
        self.clazzid = clazzid
        self.clazzname = clazzname
        self.birth = birth
        self.gender = gender
        self.phone = phone

    # 学号
    stuno = CharField(max_length=20, null=True)
    # 姓名
    name = CharField(max_length=20)
    # 班级id
    clazzid = IntegerField(null=True)
    # 班级名称
    clazzname = CharField(max_length=50, null=True)
    # 出生日期
    birth = DateField(null=True)
    # 性别
    gender = FixedCharField(max_length=1, null=True)
    # 联系方式
    phone = CharField(max_length=15, null=True)

# 创建数据库表
db.create_tables([Clazz, Student])